using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class QuestNameBtn : MonoBehaviour
{
    // 任务名称
    public Text questNameText;

    public QuestData_SO questData;
    public Text questContentText;
    private void Awake()
    {
        GetComponent<Button>().onClick.AddListener(UpdateQuestContent);
    }

    public void SetupNameText(QuestData_SO questData)
    {
        this.questData = questData;
        questNameText.text = questData.questName +
        (questData.questState == QuestState.Complete ? "(已达成)" : "") +
        (questData.questState == QuestState.Finish ? "(已结束)" : "");

    }
    /// <summary>
    /// 设置任务详情、任务需求、任务奖励
    /// </summary>
    public void UpdateQuestContent()
    {
        questContentText.text = questData.questDescription;
        // 更新任务需求文本
        QuestUI.Instance.SetupRequireTextList(questData);

        // 先销毁上一次显示出来的奖励物品 遍历奖励物品栏下的所有子物品
        foreach (Transform item in QuestUI.Instance.rewardTransform)
        {
            Destroy(item.gameObject);
        }

        foreach (var reward in questData.rewards)
        {
            QuestUI.Instance.SetupRewardItem(reward.itemData, reward.inventoryAmount);
        }

    }
}
